If you've been
building Web pages for a while, sooner or later you'll come across
a site with features you'd dearly love to include in your own.
It could be a discussion board, a site-wide search, pages that
let users enter personal details that the site stores. No amount
of tweaking in your favourite HTML editor can achieve the same
effects.
The magic that drives most of these sites are CGI programs. Because
CGI programs run on the server, instead of the users browser,
they can do almost anything.They're normally found in a directory
called the 'cgi-bin', and their power lies in getting information
from the user and doing something with it.
Over the next few issues, we're going to open the lid of the
cgi-bin, and show you how to make your site respond to users like
never before. CGI programming sounds intimidating, but all that
bin normally contains are scripts. You should be familiar with
HTML before you start, but won't need anything else.
Perl before
swine
The vast majority of CGI programs are written in a language called
Perl. It started life as a tool to help Unix system administrators
carry out routine, boring tasks. But with the advent of the Web,
people realised it could be used to create interactive online
applications. The back end of the search engine Yahoo was written
entirely in Perl - so were tons of other sites.
Unlike languages like C, Perl scripts aren't compiled into some
unintelligible binary program. Instead you just upload a text
file containing the script, and the Perl interpreter on your host's
server takes care of running it.
|
Ever wondered what that question mark and other weird stuff is doing in the URL when you're using Yahoo? That's CGI in action
|
|
|
This is important. For one thing, it makes Perl scripts easy
to modify and pass around to your friends, which in turn means
there's tons of free programs out there that, with a little modification,
will do just about anything you could wish for. It also means
they can run on any operating system, so long as it has a Perl
interpreter installed. And the Perl interpreters are free too.
We like free.
We're going to show you how to use Perl scripts on your own site
and give you just enough knowledge of the language so you can
customise them if you need to. But this isn't going to be a tutorial
on programming in Perl. If you like what you see and want to start
bashing out code yourself, there's some excellent books that'll
help (see the Resources box) and a whole online community of 'Perl
Mongers' waiting to welcome you into their (sometimes strange)
world.
There's another reason for only scratching at Perl. Although
it's powerful, well respected, and an excellent thing to have
a nodding acquaintance with, it wasn't originally built for Web
design. In recent years, a whole bunch of other languages have
been created just to handle the task of interactive Web design,
including Microsoft's Active Server Pages (ASP), Java's JSP and
a completely Open Source language called PHP. They're much easier
than Perl to learn and use, so we'll devote the third and fourth
part of this series to them.
NEXT: Setting up a server